import {
	requestNoAuth,
	request
} from '../java110Request.js';

import conf from '../../../conf/config.js'

const refreshUserByTokenUrl = conf.baseUrl + 'mall/api/login.refreshUserByToken';

const refreshOpenIdUrl = conf.baseUrl + 'mall/api/wechat.wechatRefreshOpenId';

const getOpenIdByCodeUrl = conf.baseUrl +'mall/api/wechat.getOpenIdByCode';
/**
 *  根据HCcode 刷商城回话
 */
export function refreshUserByToken(dataObj) {
		return new Promise(
			(resolve, reject) => {
				requestNoAuth({
					url: refreshUserByTokenUrl,
					method: "POST",
					data: dataObj,
					//动态数据
					success: function(res) {
						if (res.statusCode == 200) {
							resolve(res.data);
							return;
						}
						reject(res);
					},
					fail: function(e) {
						reject(e);
					}
		});
	})
}


/**
 *  根据HCcode 刷商城回话
 */
export function refreshOpenId(dataObj) {
		return new Promise(
			(resolve, reject) => {
				request({
					url: refreshOpenIdUrl,
					method: "GET",
					data: dataObj,
					//动态数据
					success: function(res) {
						if (res.statusCode == 200) {
							resolve(res.data.data);
							return;
						}
						reject(res);
					},
					fail: function(e) {
						reject(e);
					}
		});
	})
}


/**
 * 注册用户
 * add by wuxw
 * @param {Object} _data 保存 用户地址
 */
export function getOpenIdByCode(_data) {

	return new Promise((resolve, reject) => {
		request({
			url: getOpenIdByCodeUrl,
			method: "GET",
			data: _data, //动态数据
			success: function(res) {
				let _data = res.data;
				if (_data.code == 0) {
					resolve(_data);
					return;
				}
				reject(_data);
			},
			fail: function(e) {
				reject(e);
			}
		});
	})
}
